﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LCA.Community.DAL.Model;
using Microsoft.Practices.Unity;
using LCA.Community.DAL.Interfaces;

namespace LCA.Community.Web.Models
{
    public class AnswerViewModel
    {
        public AnswerViewModel(Answer answer)
        {
            Answer = answer;
        }

        public static List<AnswerViewModel> ConvertAnswersList(List<Answer> answers)
        {
            var viewModels = new List<AnswerViewModel>();
            answers.ForEach(a => viewModels.Add(MvcApplication.Container.Resolve<AnswerViewModel>(new ParameterOverrides { { "answer", a } })));

            return viewModels;        
        }

        public bool HasVoted(string userID)
        {
            return AnswersVotesRepository.HasUserVoted(userID,Answer.RowKey);
        }

        public Answer Answer { get; set; }
        public int Votes 
        { 
            get
            {
                return AnswersVotesRepository.GetAnswerVotesByAnswer(Answer.RowKey).Count();
            }
        }

        [Dependency]
        public IAnswersVotesRepository AnswersVotesRepository { get; set; }
    }
}